package com.zhaoguang.car.controller;


import com.zhaoguang.car.common.RespBean;
import com.zhaoguang.car.entity.CarImg;
import com.zhaoguang.car.service.CarService;
import com.zhaoguang.car.vo.DetailCarVo;
import com.zhaoguang.car.vo.ListCarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    CarService carService;

    @RequestMapping("/findAllCar")
    public RespBean findAllCar(int offset, int limit) {
        System.out.println("获取所有车辆");

        List<ListCarVo> result = carService.findAllCars(offset, limit);
        if (result != null) {
            return RespBean.success("查询成功", result);
        }
        return RespBean.success("查询失败");
    }

    @RequestMapping("/homeNewCar")
    public RespBean homeNewCar() {
        List<ListCarVo> result = carService.homeNewCar();
        if (result != null) {
            return RespBean.success("查询成功", result);
        }
        return RespBean.success("查询失败");
    }

    @RequestMapping("/newCarPage")
    public RespBean newCarPage() {
        List<ListCarVo> result = carService.newCarPage();
        if (result != null) {
            return RespBean.success("查询成功", result);
        }
        return RespBean.success("查询失败");
    }

    @RequestMapping("/findCarById")
    public RespBean findCarById(int carId) {
        System.out.println("查询某辆车，CarId为：" + carId);

        DetailCarVo result = carService.findCarById(carId);
        if (result != null) {
            return RespBean.success("查询成功", result);
        }
        return RespBean.success("查询失败");
    }
}
